/**
 * Created by huangzx on 2015/6/8.
 */
define('framework/rule/RuleModule', [
    'angular',
    'jquery',
    'framework/msg/GillionMsgModule'
], function (angular, $) {
    return angular.module('RuleModule', ['GillionMsgModule'])
        .factory('RuleEditService',['$window','$compile','Resource','GillionMsg', function($window,$compile,Resource,GillionMsg){
            var translate = [{">": "大于"}, {">=": "大于等于"}, {"==": "等于"}, {"<": "小于"}, {"<=": "小于等于"}, {"!=": "不等于"}, {"+": "加"},
                {"-": "减"}, {"*": "乘"}, {"/": "除"}, {"(": "("}, {")": ")"}];
            var childAttributeResource = Resource("/grule-manager/businessModelAttribute/childList/:id", {
                id: "@id"
            });
            function showThen(list){
                var thenList=[];
                for(var i=0;i<list.length;i++){
                    if(list[i].type=="setRtnValue"){
                        thenList  =thenList.concat({'type':'setRtnValue'});
                        thenList = thenList.concat(showRule(list[i].value));
                    }if(list[i].type=="comment"){
                        thenList  =thenList.concat({'type':'comment'});
                        thenList = thenList.concat(showRule(list[i].value));
                    }else if(list[i].type=="setVariable"){
                        thenList =thenList.concat({'type':'setVariable','key':list[i].key});
                        thenList = thenList.concat(showRule(list[i].value));
                    }else if(list[i].type=="setModel"){
                        thenList =thenList.concat({'type':'setModel','modelId':list[i].modelId});
                        thenList = thenList.concat(showRule(list[i].modelValue));
                    } else if(list[i].type=="breakPackage"){
                        thenList =thenList.concat({'type':list[i].type});
                    }else if(list[i].type=="breakAssembly"){
                        thenList =thenList.concat({'type':list[i].type});
                    }else if(list[i].type=="throw"){
                        thenList =thenList.concat({'type':'throw'});
                        thenList = thenList.concat(showRule(list[i].message));
                    }else if(list[i].type=="execute"){
                        if(list[i].code=='judge'||list[i].code=='elseJudge'){
                            thenList =thenList.concat({'type':'execute','code':list[i].code});
                            thenList = thenList.concat(showRule(list[i].source));
                        }else if(list[i].code=="list"){
                            thenList = thenList.concat({'type': 'execute', 'code': list[i].code, 'source': list[i].source});
                        }else if(list[i].code=="listEnd"||list[i].code=="judgeEnd"||list[i].code=="else"||list[i].code=="listBreak"||list[i].code=="listContinue"){
                            thenList = thenList.concat({'type': 'execute', 'code': list[i].code});
                        }else if(list[i].code=="list2"){
                            thenList = thenList.concat({'type': 'execute','code': list[i].code });
                            thenList = thenList.concat(showRule(list[i].value));
                        }else{
                            //code为空的情况 map使用
                            thenList = thenList.concat({'type': 'execute'});
                            thenList = thenList.concat(showRule(list[i].value));

                        }
                    }
                }
                return thenList;
            }

            function showRule(json){
                if(json==undefined){
                    return ;
                }
                var resultList=[];
                if(json.type=="parenthesis"){
                    resultList = resultList.concat({'oper':'('});
                    resultList = resultList.concat(showRule(json.expression));
                    resultList = resultList.concat({'oper':')'});
                }else if(json.type=="lastDateTime"){
                    resultList = resultList.concat(showRule(json.source));
                    resultList = resultList.concat( {'type':'lastDateTime','source':'{}'});
                }else if(json.type=="addHours"){
                    resultList = resultList.concat(showRule(json.source));
                    resultList = resultList.concat( {'type':'addHours','source':'{}','hours':json.hours});
                }else if(json.type=="countHours"){
                    resultList = resultList.concat(showRule(json.source));
                    resultList = resultList.concat( {'type':'countHours','source':'{}','hours':json.hours});
                }else if(json.type=="endsWith"){
                    resultList = resultList.concat(showRule(json.source));
                    resultList = resultList.concat( {'type':'endsWith','source':'{}','str':json.str});
                }else if(json.type=="startWith"){
                    resultList = resultList.concat(showRule(json.source));
                    resultList = resultList.concat( {'type':'startWith','source':'{}','str':json.str});
                }else if(json.type=="matchWith"){
                    resultList = resultList.concat(showRule(json.source));
                    resultList = resultList.concat( {'type':'matchWith','source':'{}','str':json.str});
                }else if(json.type=="matcher"){
                    resultList = resultList.concat(showRule(json.source));
                    resultList = resultList.concat( {'type':'matcher','source':'{}','str':json.str});
                }else if(json.type=="dateFormat"||json.type=="middleDate"||json.type=="monthDays"||json.type=="lastDayOfMonth"||json.type=="getMonth"
                    ||json.type=="listSize"||json.type=="strLength"||json.type=="checkList"||json.type=="isHolidays"||json.type=="dateToString"||json.type=="dateToWeekDay"){
                    resultList = resultList.concat({'type':json.type});
                    for(var i=0;i<json.params.length;i++){
                        resultList = resultList.concat(showRule(json.params[i]));
                    }
                }else if(json.type=="remoteService"){
                    resultList = resultList.concat({'type':'remoteService'});
                    resultList = resultList.concat(showRule(json.serviceCode));
                    for(var i=0;i<json.params.length;i++){
                        resultList = resultList.concat(showRule(json.params[i]));
                    }
                }else if(json.type=="springCloudService"){
                    resultList = resultList.concat({'type':'springCloudService'});
                    resultList = resultList.concat(showRule(json.requestMapping));
                    for(var i=0;i<json.params.length;i++){
                        resultList = resultList.concat(showRule(json.params[i]));
                    }
                }else if(json.type=="groovyShellService"){
                    resultList = resultList.concat({'type':'groovyShellService'});
                    resultList = resultList.concat(showRule(json.shellName));
                    for(var i=0;i<json.params.length;i++){
                        resultList = resultList.concat(showRule(json.params[i]));
                    }
                }else if(json.type=="JDBCService"){
                    resultList = resultList.concat({'type':'JDBCService'});
                    resultList = resultList.concat(showRule(json.sqlName));
                    for(var i=0;i<json.params.length;i++){
                        resultList = resultList.concat(showRule(json.params[i]));
                    }
                }else if(json.type=="JDBCService"){
                    resultList = resultList.concat({'type':'JDBCService'});
                    resultList = resultList.concat(showRule(json.sqlName));
                    for(var i=0;i<json.params.length;i++){
                        resultList = resultList.concat(showRule(json.params[i]));
                    }
                }else if(json.type=="Dubbo"){
                    resultList = resultList.concat({'type':'Dubbo'});
                    resultList = resultList.concat(showRule(json.dubboName));
                    for(var i=0;i<json.params.length;i++){
                        resultList = resultList.concat(showRule(json.params[i]));
                    }
                }else if(json.type=="validator"){
                    resultList = resultList.concat({'type':'validator'});
                    resultList = resultList.concat(showRule(json.validatorName));
                    for(var i=0;i<json.params.length;i++){
                        resultList = resultList.concat(showRule(json.params[i]));
                    }
                }else if(json.type=="MapPut"){
                    resultList = resultList.concat({'type':'MapPut'});
                    resultList = resultList.concat(showRule(json.map));
                    resultList = resultList.concat(showRule(json.key));
                    resultList = resultList.concat(showRule(json.value));
                }else if(json.type=="MapGet"){
                    resultList = resultList.concat({'type':'MapGet'});
                    resultList = resultList.concat(showRule(json.map));
                    resultList = resultList.concat(showRule(json.key));
                }else if(json.type=="clearList"||json.type=="clearMap"){
                    resultList = resultList.concat({'type':json.type});
                    resultList = resultList.concat(showRule(json.value));
                }else if(json.type=="newMap"||json.type=="newList"){
                    resultList = resultList.concat({'type':json.type});
                }else if(json.type=="ListAdd"){
                    resultList = resultList.concat({'type':'ListAdd'});
                    resultList = resultList.concat(showRule(json.list));
                    resultList = resultList.concat(showRule(json.value));
                }else if(json.type=="MAX"||json.type=="MIN"||json.type=="AVG"||json.type=="SUM"||json.type=='Exception'||json.type=='rounding'){
                    resultList = resultList.concat({'type':json.type});
                    for(var i=0;i<json.params.length;i++){
                        resultList = resultList.concat(showRule(json.params[i]));
                    }
                }else if(json.type=="Rule"){
                    resultList = resultList.concat({'type':'Rule'});
                    resultList = resultList.concat(showRule(json.groupId));
                    resultList = resultList.concat(showRule(json.artifactId));
                    for(var i=0;i<json.params.length;i++){
                        resultList = resultList.concat(showRule(json.params[i]));
                    }
                }else if(json.type=="templet"){
                    resultList = resultList.concat({'type':'templet','chName':json.chName});
                    for(var i=0;i<json.params.length;i++){
                        resultList = resultList.concat(showRule(json.params[i]));
                    }
                }else if(json.type=="Rate"){
                    resultList = resultList.concat({'type':'Rate'});
                    resultList = resultList.concat(showRule(json.RateValue));
                    resultList = resultList.concat(showRule(json.Rate));
                    if(json.countValue!=null){
                        resultList = resultList.concat(showRule(json.countValue));
                    }
                }else {
                    if (json.left != null || json.right != null) {
                        resultList = resultList.concat(showRule(json.left));
                        resultList = resultList.concat({'oper':json.oper});
                        resultList = resultList.concat(showRule(json.right));
                    } else {
                        resultList.push(json);
                    }
                }
                return resultList;
            }

            function setHtml($scope,list,type) {
                var conditionList =[];
                if (type == 'condition'){
                    if (list.length > 0) {
                        addConditionRow($scope,"",conditionList);
                    }
                }
                for(var i=0;i<list.length;i++){
                    if(list[i].oper!="undefined"&&list[i].oper!=null&&list[i].oper!="&&"&&list[i].oper!="||"&&list[i].oper!="unit||"&&list[i].oper!="unit&&") {
                        $scope.nowClick++;
                        $scope.countCondition++;
                        var mes=translateMes(list[i].oper);
                        setConditionList($scope,conditionList,mes,JSON.stringify(list[i]),'sign');

                    }else if(list[i].type=="model"||list[i].type=="const"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        var type;
                        if(list[i].type=="model"){
                            type="property";
                        }else{
                            type="entry";
                        }
                        setConditionList($scope,conditionList,list[i].value==""?"\'\'":list[i].value,JSON.stringify(list[i]),type);

                    }else if(list[i].type=="variable"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,list[i].variableName,JSON.stringify(list[i]),'variable');
                    }else if(list[i].type=="dict"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,list[i].value,JSON.stringify(list[i]),'dict');
                    }else if(list[i].type=="listValue"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,"获取"+list[i].source,JSON.stringify(list[i]),'special');
                    }else if(list[i].type=="listObj"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,"获取循环中对象",JSON.stringify(list[i]),'special');
                    }else if(list[i].type=="nowDate"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,"当前时间",JSON.stringify(list[i]),'method');
                    }else if(list[i].type=="lastDateTime"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,"当天最后时间",JSON.stringify(list[i]),'method');
                    }else if(list[i].type=="addHours"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        var mes
                        if(isNaN(list[i].hours)){
                            mes ="加 "+list[i].hours.value+" 小时";
                        }else{
                            mes ="加 "+list[i].hours+" 小时";
                        }
                        setConditionList($scope,conditionList,mes,JSON.stringify(list[i]),'method');

                    }else if(list[i].type=="countHours"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        var mes
                        if(isNaN(list[i].hours)){
                            mes ="加 "+list[i].hours.value+" 小时";
                        }else{
                            mes ="加 "+list[i].hours+" 小时";
                        }
                        setConditionList($scope,conditionList,mes,JSON.stringify(list[i]),'method');

                    }else if(list[i].type=="startWith"||list[i].type=="endsWith"||list[i].type=="matchWith"||list[i].type=="matcher"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        var mes
                        if(list[i].type=="startWith"){
                            mes ="以 "+list[i].str+" 开始";
                        }else if(list[i].type=="endsWith"){
                            mes ="以 "+list[i].str+" 结尾";
                        }else if(list[i].type=="matchWith"){
                            mes ="包含 "+list[i].str;
                        }else if(list[i].type=="matcher"){
                            mes ="匹配正则 "+list[i].str;
                        }
                        setConditionList($scope,conditionList,mes,JSON.stringify(list[i]),'method');

                    }else if(list[i].type=="compareHour"||list[i].type=="replaceDate"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        var mes1,mes2,mes3,type1,type2,typeValue;
                        if(list[i].source.value==undefined){
                            mes1=list[i].source.variableName;
                            type1="variable";
                        }else{
                            mes1=list[i].source.value;
                            type1="property";
                        }
                        setConditionList($scope,conditionList,mes1,JSON.stringify(list[i].source),type1);
                        $scope.nowClick++;
                        $scope.countCondition++;
                        if(list[i].type=="compareHour"){
                            mes2="小时比较";
                            typeValue="{'type':'compareHour'}";
                        }else{
                            mes2 = "替换时分秒";
                            typeValue="{'type':'replaceDate'}";
                        }
                        setConditionList($scope,conditionList,mes2,typeValue,'method');
                        $scope.nowClick++;
                        $scope.countCondition++;
                        mes3=list[i].hours.value;

                        if(list[i].hours.value===undefined){
                            mes3=list[i].hours.variableName;
                            type2="variable";
                        }else{
                            mes3=list[i].hours.value;
                            type2="property";
                        }
                        setConditionList($scope,conditionList,mes3,JSON.stringify(list[i].hours),type2);
                    }else if(list[i].type=="dateFormat"||list[i].type=="middleDate"||list[i].type=="monthDays"||list[i].type=="lastDayOfMonth"||list[i].type=="getMonth"||list[i].type=="listSize"
                        ||list[i].type=="strLength"||list[i].type=="checkList"||list[i].type=="isHolidays"||list[i].type=="dateToString"||list[i].type=="dateToWeekDay"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        var mes="";
                        if(list[i].type=="dateFormat"){
                            mes="时间格式化"
                        }if(list[i].type=="dateToString"){
                            mes="时间格式输出"
                        }else if(list[i].type=="middleDate"){
                            mes="中间时间";
                        }else if(list[i].type=="monthDays"){
                            mes="自然月天数";
                        }else if(list[i].type=="lastDayOfMonth"){
                            mes="当月最后时间";
                        }else if(list[i].type=="getMonth"){
                            mes="当前月份";
                        }else if(list[i].type=="listSize"){
                            mes="获取数组长度";
                        }else if(list[i].type=="strLength"){
                            mes="获取字符串长度";
                        }else if(list[i].type=="checkList"){
                            mes="list中元素是否重复";
                        }else if(list[i].type=="isHolidays"){
                            mes="是否节假日";
                        }else if (list[i].type == "dateToWeekDay") {
                            mes="日期为星期几"
                        }
                        setConditionList($scope,conditionList,mes,JSON.stringify(list[i]),'component');
                    }else if(list[i].type=="templet"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,list[i].chName,JSON.stringify(list[i]),'method');
                    }else if(list[i].type=="remoteService"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,'远程服务',JSON.stringify(list[i]),'component');

                    }else if(list[i].type=="springCloudService"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,'SpringCloud服务',JSON.stringify(list[i]),'component');

                    }else if(list[i].type=="groovyShellService"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,'GroovyShell组件',JSON.stringify(list[i]),'component');

                    }else if(list[i].type=="JDBCService"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,'数据库组件',JSON.stringify(list[i]),'component');

                    }else if(list[i].type=="Dubbo"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,'Dubbo服务',JSON.stringify(list[i]),'component');

                    }else if(list[i].type=="validator"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,'校验组件',JSON.stringify(list[i]),'component');
                    }else if(list[i].type=="MapPut"||list[i].type=="MapGet"||list[i].type=="ListAdd"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        var convergeStr;
                        if(list[i].type=="MapPut"){
                            convergeStr="Map设置";
                        }else if(list[i].type=="MapGet"){
                            convergeStr="Map获取";
                        }else if(list[i].type=="ListAdd"){
                            convergeStr="List添加";
                        }
                        setConditionList($scope,conditionList,convergeStr,JSON.stringify(list[i]),'component');

                    }else if(list[i].type=="newMap"||list[i].type=="newList"||list[i].type=="clearMap"||list[i].type=="clearList"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        var convergeStr;
                        if(list[i].type=="newMap"){
                            convergeStr="新建Map";
                        }else if(list[i].type=="newList"){
                            convergeStr="新建List";
                        }else if(list[i].type=="clearMap"){
                            convergeStr="清空Map";
                        }else if(list[i].type=="clearList"){
                            convergeStr="清空List";
                        }
                        setConditionList($scope,conditionList,convergeStr,JSON.stringify(list[i]),'component');

                    }else if(list[i].type=="MAX"||list[i].type=="MIN"||list[i].type=="AVG"||list[i].type=="SUM"||list[i].type=="Exception"||list[i].type=="rounding"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        var convergeStr;
                        if(list[i].type=="MAX"){
                            convergeStr = "最大值";
                        }else if(list[i].type=="MIN"){
                            convergeStr = "最小值";
                        }else if(list[i].type=="AVG"){
                            convergeStr = "平均值";
                        }else if(list[i].type=="SUM"){
                            convergeStr = "求和";
                        }else if(list[i].type=="Exception"){
                            convergeStr = "异常组件";
                        }else if(list[i].type=="rounding"){
                            convergeStr = "四舍五入";
                        }
                        setConditionList($scope,conditionList,convergeStr,JSON.stringify(list[i]),'component');
                    }else if(list[i].type=="Rule") {
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,'规则组件',JSON.stringify(list[i]),'component');
                    }else if(list[i].type=="Rate") {
                        $scope.nowClick++;
                        $scope.countCondition++;
                        setConditionList($scope,conditionList,'费率组件',JSON.stringify(list[i]),'component');
                    }else if(list[i].oper=="unit&&"||list[i].oper=="unit||") {
                        $scope.nowClick++;
                        $scope.countCondition++;
                        var mes ;
                        if(list[i].oper=="unit&&"){
                            mes ="并且"
                        }else{
                            mes = "或者"
                        }
                        setConditionList($scope,conditionList,mes,JSON.stringify(list[i]),'sign');
                    }else if(list[i].oper=="&&"){
                        $scope.nowClick++;
                        $scope.countCondition++;
                        conditionList =[];
                        addConditionRow($scope,"&&",conditionList,false);
                    }else if(list[i].oper=="||"){
                        conditionList =[];
                        addConditionRow($scope,"||",conditionList,false);
                    }else if(list[i].type=="setRtnValue"){
                        conditionList =[];
                        addThen($scope,"setRtnValue",conditionList,false);
                    }else if(list[i].type=="comment"){
                        conditionList =[];
                        addThen($scope,"comment",conditionList,false);
                    }else if(list[i].type=="throw"){
                        conditionList =[];
                        addThen($scope,"throw",conditionList,false);
                        //$scope.setConditionList(conditionList,list[i].code,"{'type':'const'}",'entry');
                    } else if(list[i].type=="execute"){
                        conditionList =[];
                        addThen($scope,"execute",conditionList,false);
                        if(list[i].code=="list"){
                            setConditionList($scope,conditionList,"循环"+list[i].source.variableName,"{'type':'list','listSource':'"+list[i].source.variableName+"'}",'special')
                        }else if(list[i].code=="list2"){
                            setConditionList($scope,conditionList,"循环","{'type':'list2'}",'special')
                        }else if(list[i].code=="listEnd"){
                            setConditionList($scope,conditionList,"循环结束","{'type':'listEnd'}",'special')

                        }else if(list[i].code=="listBreak"){
                            setConditionList($scope,conditionList,"跳出循环","{'type':'listBreak'}",'special')

                        }else if(list[i].code=="listContinue"){
                            setConditionList($scope,conditionList,"跳过当次循环","{'type':'listContinue'}",'special')

                        }else if(list[i].code=="judgeEnd"){
                            setConditionList($scope,conditionList,"判断结束","{'type':'judgeEnd'}",'special')

                        }else if(list[i].code=="else"){
                            setConditionList($scope,conditionList,"判断不成立，则","{'type':'else'}",'special')

                        }else if(list[i].code=="judge"){
                            setConditionList($scope,conditionList,"判断","{'type':'judge'}",'special')
                        }else if(list[i].code=="elseJudge"){
                            setConditionList($scope,conditionList,"否则判断","{'type':'elseJudge'}",'special')
                        }else{
                            //其他情况，code为null  目前仅有map操作
                            //$scope.setConditionList(conditionList,list[i].key,"{'type':'variable','variableName':'"+list[i].key+"'}",'variable')
                        }

                    }else if(list[i].type=="setVariable"){
                        conditionList =[];
                        addThen($scope,"setVariable",conditionList,false);
                        setConditionList($scope,conditionList,list[i].key,"{'type':'variable','variableName':'"+list[i].key+"'}",'variable')

                    }else if(list[i].type=="setModel"){
                        conditionList =[];
                        addThen($scope,"setModel",conditionList,false);
                        setConditionList($scope,conditionList,list[i].modelId,"{'type':'model','value':'"+list[i].modelId+"'}",'property')
                    }else if(list[i].type=="breakPackage"||list[i].type=="breakAssembly"){
                        conditionList =[];
                        addThen($scope,list[i].type,conditionList,false);
                    }
                }
            }

            function  translateMes(value) {
                var mes;
                angular.forEach(translate, function (data) {
                    for (var key in data) {
                        if (key == value) {
                            mes = data[key];
                            break;
                        }
                    }
                });
                return mes;
            }

            function addConditionRow($scope,type,conditionList,isButton){
                $scope.count++;
                $scope.countCondition++;
                init($scope);
                $scope.conditionRows.push({
                    _id: $scope.count,
                    countCondition: $scope.countCondition,
                    conditions:conditionList,
                    sign:type,
                    isButton:isButton
                });
            }

            function addThen($scope,type,thenList,isButton){
                $scope.count++;
                $scope.countCondition++;
                init($scope);
                var isExecute = $scope.executeRow.indexOf($scope.thenRows.length+1)>-1;
                console.log( $scope.executeRow.length+"|"+isExecute);
                $scope.thenRows.push({
                    _id: $scope.count,
                    countCondition: $scope.countCondition,
                    conditions:thenList,
                    sign:type,
                    isButton:isButton,
                    isExecute:isExecute
                });
                //checkRule();
            }

            function init($scope){
                $scope.showNone=true;
                $scope.showSign=false;
                $scope.showProperty=false;
                $scope.showEntry=false;
                $scope.showAllCondition=false;
                $scope.showMethod=false;
                $scope.showComponent=false;
                $scope.showSpecial=false;
                $scope.showDict=false;
            }
            //关闭下拉框 并且或者类下拉框使用
            function closeChange(click){
                var element = angular.element("#" + click).parent().children();
                for(var i=1;i<element.length;i++){
                    element[i].remove();
                }
            }
            function changeThen($scope,click){
                angular.element("#then" + click).parent().bind("mouseleave", function (){
                    closeChange("then"+click);
                });
                var sign ;
                var mes;
                var type;
                if(angular.element("#then"+click).text()==="返回：") {
                    sign=["setVariable","breakPackage","breakAssembly","setModel","throw","execute","comment"];
                    mes=["变量赋值：","跳出规则包。","跳出规则集。","属性赋值：","抛出异常：","执行：","注释："];
                    type=["setValue","break","break","setValue","throw","execute"];
                }else if(angular.element("#then"+click).text()==="变量赋值："){
                    sign=["setRtnValue","breakPackage","breakAssembly","setModel","throw","execute","comment"];
                    mes=["返回：","跳出规则包。","跳出规则集。","属性赋值：","抛出异常：","执行：","注释："];
                    type=["return","break","break","setValue","throw","execute"];
                }else if(angular.element("#then"+click).text()==="跳出规则包。"){
                    sign=["setRtnValue","setVariable","breakAssembly","setModel","throw","execute","comment"];
                    mes=["返回：","变量赋值：","跳出规则集。","属性赋值：","抛出异常：","执行：","注释："];
                    type=["return","setValue","break","setValue","throw","execute"];
                }else if(angular.element("#then"+click).text()==="跳出规则集。"){
                    sign=["setRtnValue","breakPackage","setRtnValue","setModel","throw","execute","comment"];
                    mes=["返回：","跳出规则包。","变量赋值：","属性赋值：","抛出异常：","执行：","注释："];
                    type=["return","break","setValue","setValue","throw","execute"];
                }else if(angular.element("#then"+click).text()==="属性赋值："){
                    sign=["setRtnValue","breakPackage","setVariable","breakAssembly","throw","execute","comment"];
                    mes=["返回：","跳出规则包。","变量赋值：","跳出规则集。","抛出异常：","执行：","注释："];
                    type=["return","break","setValue","break","throw","execute"];
                }else if(angular.element("#then"+click).text()==="抛出异常："){
                    sign=["setRtnValue","breakPackage","setVariable","breakAssembly","setModel","execute","comment"];
                    mes=["返回：","跳出规则包。","变量赋值：","跳出规则集。","属性赋值：","执行：","注释："];
                    type=["return","break","setValue","break","setValue","execute"];
                }else if(angular.element("#then"+click).text()==="执行："){
                    sign=["setRtnValue","breakPackage","setVariable","breakAssembly","setModel","throw","comment"];
                    mes=["返回：","跳出规则包。","变量赋值：","跳出规则集。","属性赋值：","抛出异常：","注释："];
                    type=["return","break","setValue","break","setValue","throw"];
                }
                else if(angular.element("#then"+click).text()==="注释："){
                    sign=["setRtnValue","breakPackage","setVariable","breakAssembly","setModel","throw","execute"];
                    mes=["返回：","跳出规则包。","变量赋值：","跳出规则集。","属性赋值：","抛出异常：","执行："];
                    type=["return","break","setValue","break","setValue","throw"];
                }
                angular.element("#then" + click).after(
                    $compile(
                        "<div class='also-open'>" +
                        "<div class='also-open-a'><a href='javascript:void(0)' ng-click='selectResultType(&apos;"+sign[0]+"&apos;,&apos;"+mes[0]+"&apos;,&apos;"+click+"&apos;,&apos;"+type[0]+"&apos;)'>"+mes[0]+"</a></div>" +
                        "<div class='also-open-a'><a href='javascript:void(0)' ng-click='selectResultType(&apos;"+sign[1]+"&apos;,&apos;"+mes[1]+"&apos;,&apos;"+click+"&apos;,&apos;"+type[1]+"&apos;)'>"+mes[1]+"</a></div>" +
                        "<div class='also-open-a'><a href='javascript:void(0)' ng-click='selectResultType(&apos;"+sign[2]+"&apos;,&apos;"+mes[2]+"&apos;,&apos;"+click+"&apos;,&apos;"+type[2]+"&apos;)'>"+mes[2]+"</a></div>" +
                        "<div class='also-open-a'><a href='javascript:void(0)' ng-click='selectResultType(&apos;"+sign[3]+"&apos;,&apos;"+mes[3]+"&apos;,&apos;"+click+"&apos;,&apos;"+type[3]+"&apos;)'>"+mes[3]+"</a></div>" +
                        "<div class='also-open-a'><a href='javascript:void(0)' ng-click='selectResultType(&apos;"+sign[4]+"&apos;,&apos;"+mes[4]+"&apos;,&apos;"+click+"&apos;,&apos;"+type[4]+"&apos;)'>"+mes[4]+"</a></div>" +
                        "<div class='also-open-a'><a href='javascript:void(0)' ng-click='selectResultType(&apos;"+sign[5]+"&apos;,&apos;"+mes[5]+"&apos;,&apos;"+click+"&apos;,&apos;"+type[5]+"&apos;)'>"+mes[5]+"</a></div>" +
                        "<div class='also-open-a'><a href='javascript:void(0)' ng-click='selectResultType(&apos;"+sign[6]+"&apos;,&apos;"+mes[6]+"&apos;,&apos;"+click+"&apos;,&apos;"+type[6]+"&apos;)'>"+mes[6]+"</a></div>" +
                        "</div>"
                    )($scope)
                )
            }

            function setConditionList($scope,conditionList,mes,value,type){
                conditionList.push({
                    countCondition: $scope.countCondition,
                    mes:mes,
                    value:value,
                    type:type
                });
            }

            function change($scope,click){
                angular.element("#symbol" + click).parent().bind("mouseleave", function (){
                    closeChange("symbol"+click);
                });
                var sign ;
                var mes;
                if(angular.element("#symbol"+click).text()=="或者") {
                    sign="&&";
                    mes="并且";
                }else if(angular.element("#symbol"+click).text()=="并且"){
                    sign="||";
                    mes="或者";
                }
                angular.element("#symbol" + click).after(
                    $compile(
                        "<div class='also-open'>" +
                        "<div class='also-open-a'><a href='javascript:void(0)' ng-click='selectLogicalSign(&apos;"+sign+"&apos;,&apos;"+mes+"&apos;,&apos;"+click+"&apos;)'>"+mes+"</a></div>" +
                        "</div>"
                    )($scope)
                )
            }

            function addRowCondition($scope,index){
                if(index==0){//首行删减处理
                    $scope.conditionRows[index].sign="&&";
                }
                $scope.count++;
                $scope.countCondition++;
                init($scope);
                $scope.conditionRows.splice(index, 0,{
                    _id: $scope.count,
                    countCondition: $scope.countCondition,
                    conditions:"",
                    sign:"&&",
                    isButton:true
                });
            }
            function addRowThen($scope,index){
                $scope.count++;
                $scope.countCondition++;
                init($scope);
                $scope.thenRows.splice(index, 0,{
                    _id: $scope.count,
                    countCondition: $scope.countCondition,
                    conditions:"",
                    sign:"setRtnValue",
                    isButton:true
                });
            }

            function upThen($scope,index){
                if(index==0){
                    return;
                }
                var tmp =$scope.thenRows[index-1];
                $scope.thenRows[index-1]=$scope.thenRows[index];
                $scope.thenRows[index]=tmp;
            }
            function downThen($scope,index){
                if(index==$scope.thenRows.length-1){
                    return;
                }
                var tmp =$scope.thenRows[index+1];
                $scope.thenRows[index+1]=$scope.thenRows[index];
                $scope.thenRows[index]=tmp;
            }
            function upCondition($scope,index){
                if(index==0){
                    return;
                }
                if(index==1){
                    var tmp = $scope.conditionRows[index - 1];
                    tmp.sign="&&";
                    $scope.conditionRows[index - 1] = $scope.conditionRows[index];
                    $scope.conditionRows[index - 1].sign="";
                    $scope.conditionRows[index] = tmp;
                }else {
                    var tmp = $scope.conditionRows[index - 1];
                    $scope.conditionRows[index - 1] = $scope.conditionRows[index];
                    $scope.conditionRows[index] = tmp;
                }
            }
            function downCondition($scope,index){
                if(index==$scope.conditionRows.length-1){
                    return;
                }
                if(index==0){
                    var tmp = $scope.conditionRows[index + 1];
                    tmp.sign="";
                    $scope.conditionRows[index + 1] = $scope.conditionRows[index];
                    $scope.conditionRows[index + 1].sign="&&";
                    $scope.conditionRows[index] = tmp;
                }else {
                    var tmp = $scope.conditionRows[index + 1];
                    $scope.conditionRows[index + 1] = $scope.conditionRows[index];
                    $scope.conditionRows[index] = tmp;
                }
            }
            function copyCRow($scope,index){
                $scope.count++;
                $scope.countCondition++;
                var row ={};
                angular.copy($scope.conditionRows[index],row);
                row._id =$scope.count;
                row.countCondition = $scope.countCondition;
                if(row.sign==""){
                    row.sign="&&";
                }
                for(var i=0;i<row.conditions.length;i++){
                    $scope.countCondition++;
                    row.conditions[i].countCondition = $scope.countCondition;
                }
                $scope.conditionRows.splice(index+1,0,row);
            }
            function copyTRow($scope,index){
                var row ={};
                angular.copy($scope.thenRows[index],row);
                row._id =$scope.count;
                row.countCondition = $scope.countCondition;

                for(var i=0;i<row.conditions.length;i++){
                    $scope.countCondition++;
                    row.conditions[i].countCondition = $scope.countCondition;
                }
                $scope.thenRows.splice(index+1,0,row);
            }
            function show($scope,type,model,showType){
                $("#shadeCondition").css({ display: "block"});
                var list = document.getElementsByName("column");
                for(var i=0; i< list.length; i++){
                    list[i].className = "";
                }
                document.getElementById("radioString").checked=true;
                if(type=='sign'){
                    document.getElementById(type).setAttribute("class","on");
                    $scope.showNone=false;
                    $scope.showAllCondition=true;
                    $scope.showProperty=false;
                    $scope.showSign=true;
                    $scope.showEntry=false;
                    $scope.showVariable=false;
                    $scope.showMethod=false;
                    $scope.showComponent=false;
                    $scope.showSpecial=false;
                    $scope.showDict= false;
                }else if(type=='entry'){
                    document.getElementById(type).setAttribute("class","on");
                    $scope.showNone=false;
                    $scope.showAllCondition=true;
                    $scope.showProperty=false;
                    $scope.showSign=false;
                    $scope.showEntry=true;
                    $scope.showVariable=false;
                    $scope.showMethod=false;
                    $scope.showComponent=false;
                    $scope.showSpecial=false;
                    $scope.showDict= false;
                    if(event.target.name=="node") {
                        $scope.textEntry = event.target.text;
                        if (JSON.parse(event.target.attributes.value.value).valueType === "Number") {
                            $("input[value='Number']").prop('checked', true);
                        }
                    }
                }else if(type=='property'){
                    document.getElementById(type).setAttribute("class","on");
                    $scope.showNone=false;
                    $scope.showAllCondition=true;
                    $scope.showProperty=true;
                    $scope.showSign=false;
                    $scope.showEntry=false;
                    $scope.showVariable=false;
                    $scope.showMethod=false;
                    $scope.showComponent=false;
                    $scope.showSpecial=false;
                    $scope.showDict= false;
                }else if (type=='variable'){
                    document.getElementById(type).setAttribute("class","on");
                    $scope.showNone=false;
                    $scope.showAllCondition=true;
                    $scope.showProperty=false;
                    $scope.showSign=false;
                    $scope.showEntry=false;
                    $scope.showVariable=true;
                    $scope.showMethod=false;
                    $scope.showComponent=false;
                    $scope.showSpecial=false;
                    $scope.showDict= false;
                }else if (type=='method'){
                    document.getElementById(type).setAttribute("class","on");
                    $scope.showNone=false;
                    $scope.showAllCondition=true;
                    $scope.showProperty=false;
                    $scope.showSign=false;
                    $scope.showEntry=false;
                    $scope.showVariable=false;
                    $scope.showMethod=true;
                    $scope.showComponent=false;
                    $scope.showSpecial=false;
                    $scope.showDict= false;
                }else if (type=='component'){
                    document.getElementById(type).setAttribute("class","on");
                    $scope.showNone=false;
                    $scope.showAllCondition=true;
                    $scope.showProperty=false;
                    $scope.showSign=false;
                    $scope.showEntry=false;
                    $scope.showVariable=false;
                    $scope.showMethod=false;
                    $scope.showComponent=true;
                    $scope.showSpecial=false;
                    $scope.showDict= false;
                }else if (type=='special'){
                    document.getElementById(type).setAttribute("class","on");
                    $scope.showNone=false;
                    $scope.showAllCondition=true;
                    $scope.showProperty=false;
                    $scope.showSign=false;
                    $scope.showEntry=false;
                    $scope.showVariable=false;
                    $scope.showMethod=false;
                    $scope.showComponent=false;
                    $scope.showSpecial=true;
                    $scope.showDict= false;
                }else if (type=='dict'){
                    document.getElementById(type).setAttribute("class","on");
                    $scope.showNone=false;
                    $scope.showAllCondition=true;
                    $scope.showProperty=false;
                    $scope.showSign=false;
                    $scope.showEntry=false;
                    $scope.showVariable=false;
                    $scope.showMethod=false;
                    $scope.showComponent=false;
                    $scope.showSpecial=false;
                    $scope.showDict= true;
                }else{
                    $scope.nowClick = type;
                    $scope.clickType=model;//记录按钮或者节点点击，判断是否添加条件选择按钮

                    if(model=="button") {
                        var doc = angular.element("#showCondition" + $scope.nowClick);
                        //添加高亮样式
                        doc.addClass("attribute-check");
                        doc.text("右侧边栏选择");
                        showType="property";
                    }else if(model=="node"){
                        var doc = angular.element("#node" + $scope.nowClick);
                        //添加高亮样式
                        doc.addClass("attribute-check");
                        closeEdit("node","edit");
                    }
                    $scope.show(showType);
                }
            }
            function viewObject($scope,id,margin){
                if($("#"+id).text()=="对象[-]"){
                    angular.element("#son"+id).text("");
                    $("#"+id).text("对象[+]");
                    return;
                }
                $("#"+id).text("对象[-]");
                childAttributeResource.get({
                    id: id
                }, function (response) {
                    if (response.success) {
                        var records = response.data;
                        angular.forEach(records, function (item){
                            if(item.dataType!='Object'){
                                angular.element("#son"+id).append(
                                    $compile(
                                        "<div class='model-value model-value-son' style='margin-left:"+20*margin+"px'>"+
                                        "<div class='model-value-l'><button type='button' class='engine-btn-model' ng-click='addModel(&apos;"+item.name+"&apos;)'>"+item.dataType+"</button></div>"+
                                        "<div class='model-value-r'>"+item.name+"</div>"+
                                        "<div class='clear'></div>"+
                                        "</div>"
                                    )($scope)
                                )
                            }else{
                                angular.element("#son"+id).append(
                                    $compile(
                                        "<div class='model-value model-value-son' style='margin-left:"+20*margin+"px'>"+
                                        "<div class='model-value-l'><button type='button' id='"+item.id+"' ng-click='viewObject(&apos;"+item.id+"&apos;,"+(margin+1)+")' class='engine-btn-model'>对象[+]</button></div>"+
                                        "<div class='model-value-r'ng-click='addModel(&apos;"+item.name+"&apos;)'>"+item.name+"</div>"+
                                        "<div class='clear'></div>"+
                                        "</div>"+
                                        "<div id='son"+item.id+"'></div>"
                                    )($scope)
                                )
                            }
                        })
                    }
                });
            }
            function addButton($scope){
                $scope.countCondition++;
                if($scope.clickType=="button") {
                    angular.element("#click" + $scope.nowClick).after(
                        $compile(
                            "<span class='attribute'  id='click" + $scope.countCondition + "' ><button type='button' name ='addButton' id='showCondition" +  $scope.countCondition + "' ng-click='show(" + $scope.countCondition + ",&apos;button&apos;)' class='engine-btn-default'>点击选择</button></span>"
                        )($scope)
                    );
                }
            }

            function addEntry($scope) {
                var expression;
                document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                angular.element("#node" + $scope.nowClick).removeClass("attribute-check");
                var valueType = $('input:radio:checked').val();
                if ($scope.textEntry == "\"\"") {
                    expression = "{&quot;type&quot;:&quot;const&quot;,&quot;value&quot;:&quot;&quot;,&quot;valueType&quot;:&quot;String&quot;}";
                } else {
                    expression = "{&quot;type&quot;:&quot;const&quot;,&quot;value&quot;:&quot;" + $scope.textEntry + "&quot;,&quot;valueType&quot;:&quot;" + valueType + "&quot;}";
                }
                angular.element("#click" + $scope.nowClick).html(
                    $compile(
                        "<a href='javascript:void(0)' name='node' id='node" + $scope.nowClick + "' ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;entry&apos;)' type='entry'      value='" + expression + "'>" + $scope.textEntry + "</a>"
                    )($scope)
                );
                $scope.textEntry = "";
                afterAdd($scope);
            }

            function addDict($scope,item){
                var  expression = "{'type':'dict','value':'"+item.code+"'}";
                angular.element("#click" + $scope.nowClick).html(
                    $compile(
                        "<a href='javascript:void(0)' name='node' id='node"+$scope.nowClick+"' ng-click='show(&apos;"+$scope.nowClick+"&apos;,&apos;node&apos;,&apos;dict&apos;)' type='dict'      value="+expression+">"+item.code+"</a>"
                    )($scope)
                );
                afterAdd($scope);
            }

            function addSign($scope,value){
                document.getElementById('click'+$scope.nowClick).setAttribute("class","attribute");
                angular.element("#node" + $scope.nowClick).removeClass("attribute-check");
                var mes=translateMes(value);
                angular.element("#click" + $scope.nowClick).html(
                    $compile(
                        "<a href='javascript:void(0)' name='node'  id='node"+$scope.nowClick+"'  ng-click='show(&apos;"+$scope.nowClick+"&apos;,&apos;node&apos;,&apos;sign&apos;)'  type='sign'       value='{&apos;oper&apos;:&apos;"+value+"&apos;}'>"+mes+"</a>"
                    )($scope)
                )
                afterAdd($scope);
            }


            function addModel($scope,value){
                document.getElementById('click'+$scope.nowClick).setAttribute("class","attribute");
                angular.element("#node" + $scope.nowClick).removeClass("attribute-check");
                angular.element("#click" + $scope.nowClick).html(
                    $compile(
                        "<a href='javascript:void(0)' name='node'  id='node"+$scope.nowClick+"'  ng-click='show(&apos;"+$scope.nowClick+"&apos;,&apos;node&apos;,&apos;property&apos;)' type='property'      value='{&apos;type&apos;:&apos;model&apos;,&apos;value&apos;:&apos;"+value+"&apos;}'>"+value+"</a>"
                    )($scope)
                )
                afterAdd($scope);
            }
            function addVariable($scope,value){
                document.getElementById('click'+$scope.nowClick).setAttribute("class","attribute");
                angular.element("#node" + $scope.nowClick).removeClass("attribute-check");
                angular.element("#click" + $scope.nowClick).html(
                    $compile(
                        "<a href='javascript:void(0)' name='node'  id='node"+$scope.nowClick+"'  ng-click='show(&apos;"+$scope.nowClick+"&apos;,&apos;node&apos;,&apos;variable&apos;)' type='variable'       value='{&apos;type&apos;:&apos;variable&apos;,&apos;variableName&apos;:&apos;"+value+"&apos;}'>"+value+"</a>"
                    )($scope)
                )
                afterAdd($scope);
            }
            function addMethod($scope,value,text){
                angular.element("#node" + $scope.nowClick).removeClass("attribute-check");
                if(value=='addHours') {
                    var hour = document.getElementById("addHours").value;
                    var expression;
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    if(isNaN(hour)){
                        expression="{'type':'"+value+"','source':'{}','hours':{'type':'model','value':'"+hour+"'}}";
                    }else{
                        expression="{'type':'"+value+"','source':'{}','hours':'"+hour+"'}";
                    }
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;method&apos;)' type='method' value="+expression+">加 " + hour + " 小时</a>"
                        )($scope)
                    )
                }else if(value=='countHours') {
                    var hour = document.getElementById("countHours").value;
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    var expression="{'type':'"+value+"','source':'{}','hours':'"+hour+"'}";
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;method&apos;)' type='method' value="+expression+">加 " + hour + " 小时</a>"
                        )($scope)
                    )
                }else if(value=='lastDateTime'){
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;method&apos;)' type='method'       value='{&apos;type&apos;:&apos;"+value+"&apos;,&apos;source&apos;:&apos;{}&apos;}'>"+text+"</a>"
                        )($scope)
                    )
                }else if(value=='nowDate'||value=='compareHour'||value=='replaceDate'){
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;method&apos;)' type='method' value='{&apos;type&apos;:&apos;"+value+"&apos;}'>"+text+"</a>"
                        )($scope)
                    )
                }else if(value=="remoteService"||value=="springCloudService"||value=="groovyShellService"||value=="JDBCService"||value=='Rule'||value=='Rate'||value=='MAX'||value=='MIN'||value=='AVG'||value=='SUM'||value=='MapPut'||value=='MapGet'||value=='Exception'||
                    value=='ListAdd'||value=='Dubbo'||value=='validator'||value=='dateFormat'||value=='middleDate'||value=='monthDays'||value=='newList'||value=='newMap'||value=='clearList'||value=='clearMap'
                    ||value=='lastDayOfMonth'||value=='getMonth'||value=='listSize'||value=='strLength'||value=='checkList'||value=='isHolidays'||value=='dateToString'||value=='rounding'||value=='dateToWeekDay' ){
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;component&apos;)' type='component' value='{&apos;type&apos;:&apos;"+value+"&apos;}'>"+text+"</a>"
                        )($scope)
                    )
                }else if(value=='startWith') {
                    var str = document.getElementById("startWith").value;
                    var expression;
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    expression="{'type':'"+value+"','source':'{}','str':'"+str+"'}";
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;method&apos;)' type='method' value="+expression+">以 " + str + " 开始</a>"
                        )($scope)
                    )
                }else if(value=='endsWith') {
                    var str = document.getElementById("endsWith").value;
                    var expression;
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    expression="{'type':'"+value+"','source':'{}','str':'"+str+"'}";
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;method&apos;)' type='method' value="+expression+">以 " + str + " 结束</a>"
                        )($scope)
                    )
                }else if(value=='matchWith') {
                    var str = document.getElementById("matchWith").value;
                    var expression;
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    expression="{'type':'"+value+"','source':'{}','str':'"+str+"'}";
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;method&apos;)' type='method' value="+expression+">包含 " + str + "</a>"
                        )($scope)
                    )
                }else if(value=='matcher') {
                    var str = document.getElementById("matcher").value;
                    var expression;
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    expression="{'type':'"+value+"','source':'{}','str':'"+str+"'}";
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;method&apos;)' type='method' value="+expression+">匹配正则 " + str + "</a>"
                        )($scope)
                    )
                }else if(value=='list'){
                    var str = document.getElementById("loopList").value;
                    var expression;
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    expression="{'type':'"+value+"','listSource':'"+str+"'}";
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;list&apos;)' type='special' value="+expression+">循环 " + str + "</a>"
                        )($scope)
                    )
                }else if(value=='list2'){
                    var expression;
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    expression="{'type':'"+value+"'}";
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;list&apos;)' type='special' value="+expression+">循环 </a>"
                        )($scope)
                    )
                }else if(value=='listValue'){
                    var str = document.getElementById("listValue").value;
                    var expression;
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    expression="{'type':'"+value+"','source':'"+str+"'}";
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;list&apos;)' type='special' value="+expression+">获取 " + str + "</a>"
                        )($scope)
                    )
                }else if(value=='listObj'){
                    var expression;
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    expression="{'type':'"+value+"'}";
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;list&apos;)' type='special' value="+expression+">获取循环中对象</a>"
                        )($scope)
                    )
                }else if(value=='listEnd'||value=='listBreak'||value=='listContinue'){
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    if(value=='listEnd'){
                        expression="{'type':'listEnd'}";
                    }else if(value=='listBreak'){
                        expression="{'type':'listBreak'}";
                    }else if(value=='listContinue'){
                        expression="{'type':'listContinue'}";
                    }
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;list&apos;)' type='special' value="+expression+"> "+text+"</a>"
                        )($scope)
                    )
                }
                else if(value=='judge'||value=='elseJudge'){
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    if(value=="judge"){
                        expression="{'type':'judge','left':{},'right':{},'oper':''}";
                    }else if(value = "elseJudge"){
                        expression="{'type':'elseJudge','left':{},'right':{},'oper':''}";
                    }
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;list&apos;)' type='special' value="+expression+"> "+text+"</a>"
                        )($scope)
                    )
                }
                else if(value=='judgeEnd'||value=='else'){
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    if(value=='judgeEnd'){
                        expression="{'type':'judgeEnd'}";
                    }else if(value=='else'){
                        expression="{'type':'else'}";
                    }
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;list&apos;)' type='special' value="+expression+"> "+text+"</a>"
                        )($scope)
                    )
                }
                else if(value=='&&'||value=='||'){
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    var mes;
                    if(value=='&&') {
                        expression = "{'oper':'unit&&'}";
                        mes = "并且"
                    }else{
                        expression = "{'oper':'unit||'}";
                        mes="或者";
                    }
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;sign&apos;)' type='sign' value="+expression+"> "+mes+"</a>"
                        )($scope)
                    )
                }else{
                    document.getElementById('click' + $scope.nowClick).setAttribute("class", "attribute");
                    expression="{'type':'templet','chName':'"+text+"'}";
                    angular.element("#click" + $scope.nowClick).html(
                        $compile(
                            "<a href='javascript:void(0)' name='node'  id='node" + $scope.nowClick + "'  ng-click='show(&apos;" + $scope.nowClick + "&apos;,&apos;node&apos;,&apos;method&apos;)' type='method' value="+expression+">"+text+"</a>"
                        )($scope)
                    )
                }
                afterAdd($scope);
            }
            function afterAdd($scope){
                $scope.isMes=true;
                angular.element("#click" + $scope.nowClick).bind("mouseleave", function (){
                    closeEdit('node',"edit");
                });
                angular.element("#click" + $scope.nowClick).bind("mouseenter",function (){
                    showEdit($scope,'node');
                });
                if(!$scope.showButton) {
                    $scope.addButton();
                }
                $scope.showButton=false;
                $("#shadeCondition").css({ display: "none"});
                init($scope);
            }
            function addFront($scope,value){
                $("#shadeCondition").css({ display: "block"});
                init($scope);
                $scope.countCondition++;
                angular.element("#click" + value).before(
                    $compile(
                        "<span  id='click" + $scope.countCondition + "' ><button type='button' id='showCondition" +  $scope.countCondition  + "' ng-click='show(&apos;" + $scope.countCondition + "&apos;,&apos;button&apos;)' class='engine-btn-default attribute-check'>右侧边栏选择</button></span>"
                    )($scope)
                );
                $scope.showButton=true;  //控制是否带出按钮  ， 区分 前后编辑和 普通编辑的区别,前后编辑选中后不添加按钮
                $scope.show($scope.countCondition,"button","sign");
            }
            function addBehind($scope,value){
                $("#shadeCondition").css({ display: "block"});
                init($scope);
                $scope.countCondition++;
                angular.element("#click" + value).after(
                    $compile(
                        "<span  id='click" + $scope.countCondition + "'><button type='button' id='showCondition" + $scope.countCondition  + "' ng-click='show(&apos;" + $scope.countCondition + "&apos;,&apos;button&apos;)' class='engine-btn-default attribute-check'>右侧边栏选择</button></span>"
                    )($scope)
                );
                $scope.showButton=true;  //控制是否带出按钮  ， 区分 前后编辑和 普通编辑的区别
                $scope.show($scope.countCondition,"button","sign");
            }

            function getCondition(list){
                var resultList=[];
                resultList = handleParenthesis(list);
                resultList = outParenthesis(resultList);
                return resultList;
            }


            function handleParenthesis(list){
                var result=[];
                var resultList=[];
                var leftBrackets =[];
                var brackets=[];
                for(var i=0;i<list.length;i++){
                    if(list[i].oper!=null&&list[i].oper=="("){
                        leftBrackets.push(i);
                    }else if(list[i].oper!=null&&list[i].oper==")"){
                        var model = {};
                        model.left = leftBrackets.pop();
                        model.right = i;
                        brackets.push(model);
                    }
                }
                if(brackets.length>0) {
                    for (var i = 0; i < list.length; i++) {
                        if (i >= brackets[0].left && i <= brackets[0].right) {
                            i = brackets[0].right+1;
                            resultList.push(setParenthesis(list.slice(brackets[0].left+1, brackets[0].right)));
                        }
                        if(i<list.length) {
                            resultList.push(list[i]);
                        }
                    }
                    return handleParenthesis(resultList)
                }
                return list;
            }

            function setParenthesis(list){
                var result={"type": "parenthesis", "expression": {}};
                if(list[0].type=="remoteService"){
                    result.expression={"type":"remoteService","serviceCode":list[1],"params":[]};
                    for(var i=2;i<list.length;i++){
                        result.expression.params.push(list[i]);
                    }
                }else if(list[0].type=="springCloudService"){
                    result.expression={"type":"springCloudService","requestMapping":list[1],"params":[]};
                    for(var i=2;i<list.length;i++){
                        result.expression.params.push(list[i]);
                    }
                }else if(list[0].type=="groovyShellService"){
                    result.expression={"type":"groovyShellService","shellName":list[1],"params":[]};
                    for(var i=2;i<list.length;i++){
                        result.expression.params.push(list[i]);
                    }
                }else if(list[0].type=="JDBCService"){
                    result.expression={"type":"JDBCService","sqlName":list[1],"params":[]};
                    for(var i=2;i<list.length;i++){
                        result.expression.params.push(list[i]);
                    }
                }else if(list[0].type=="Dubbo"){
                    result.expression={"type":"Dubbo","dubboName":list[1],"params":[]};
                    for(var i=2;i<list.length;i++){
                        result.expression.params.push(list[i]);
                    }
                }else if(list[0].type=="validator"){
                    result.expression={"type":"validator","validatorName":list[1],"params":[]};
                    for(var i=2;i<list.length;i++){
                        result.expression.params.push(list[i]);
                    }
                }else if(list[0].type=="Rule") {
                    result.expression={"type":"Rule","groupId":list[1],"artifactId":list[2],"params":[]};
                    for(var i=3;i<list.length;i++){
                        result.expression.params.push(list[i]);
                    }
                }else if(list[0].type=="Rate") {
                    if(list.length==3) {
                        result.expression = {"type": "Rate", "RateValue": list[1], "Rate": list[2]};
                    }else{
                        result.expression = {"type": "Rate", "RateValue": list[1], "Rate": list[2],"countValue":list[3]};
                    }
                }else if(list[0].type=="MAX"||list[0].type=="MIN"||list[0].type=="SUM"||list[0].type=="AVG"||list[0].type=="Exception"||list[0].type=="rounding") {
                    result.expression={"type":list[0].type,"params":[]};
                    for(var i=1;i<list.length;i++){
                        result.expression.params.push(list[i]);
                    }
                }else if(list[0].type=="MapGet"){
                    result.expression={"type":list[0].type,"map":list[1],"key":list[2]};
                }else if(list[0].type=="MapPut"){
                    //result.expression={"type":list[0].type,"map":list[1],"key":list[2],"value":list[3]};

                    result.expression={"type":list[0].type,"map":list[1],"key":list[2],"value":outParenthesis(list.slice(3,list.length))};
                }else if(list[0].type=="ListAdd"){
                    result.expression={"type":list[0].type,"list":list[1],"value":list[2]};
                }else if(list[0].type=="newList"||list[0].type=="newMap"||list[0].type=="clearList"||list[0].type=="clearMap"){
                    result.expression={"type":list[0].type,"value":list[1]};
                }else if(list[0].type=="dateFormat"||list[0].type=="middleDate"||list[0].type=="monthDays"||list[0].type=="lastDayOfMonth"||list[0].type=="getMonth"||list[0].type=="listSize"
                    ||list[0].type=="strLength"||list[0].type=="checkList"||list[0].type=="isHolidays"||list[0].type=="dateToString"||list[0].type=="dateToWeekDay"){
                    result.expression={"type":list[0].type,"params":[]};
                    for(var i=1;i<list.length;i++){
                        result.expression.params.push(list[i]);
                    }
                }else if(list[0].type=="templet"){
                    result.expression = {"type": "templet", "chName": list[0].chName, "params":[]};
                    for(var i=1;i<list.length;i++){
                        result.expression.params.push(list[i]);
                    }
                }else {
                    result.expression = outParenthesis(list);
                }
                return result;
            }

            function getResult(resultlList){
                var list =[];
                var thenList = [];
                var flag=0;
                if(resultlList.length==1){
                    list.push(resultlList.slice(0, 1));
                }else {
                    for (var i = 1; i < resultlList.length; i++) {
                        if (resultlList[i].type == "execute"||resultlList[i].type == "throw"||resultlList[i].type == "setVariable" || resultlList[i].type == "setRtnValue" ||
                            resultlList[i].type == "breakPackage" || resultlList[i].type == "breakAssembly" || resultlList[i].type == "setModel"||resultlList[i].type == "comment") {
                            list.push(resultlList.slice(flag, i));
                            flag = i;
                        }
                        if (i == resultlList.length - 1) {
                            list.push(resultlList.slice(flag, resultlList.length));
                        }
                    }
                }
                for(var i=0;i<list.length;i++){
                    var list0=list[i];
                    var list1=[];

                    var model={};
                    model.type = list0[0].type;
                    if(model.type=='setVariable'){
                        model.key = list0[1].variableName;//设置变量赋值时使用
                        list1=handleParenthesis(list0.slice(2,list0.length));
                        list1=outParenthesis(list1);
                        model.value =list1;
                    }else if(model.type=='setModel'){
                        model.modelId= list0[1].value;//设置属性时使用
                        list1=handleParenthesis(list0.slice(2,list0.length));
                        list1=outParenthesis(list1);
                        model.modelValue=list1;
                    }else if(model.type=='throw'){n
                        list1=handleParenthesis(list0.slice(1,list0.length));
                        list1=outParenthesis(list1);
                        model.message=list1;
                    }else if(model.type=='setRtnValue'){
                        list1=handleParenthesis(list0.slice(1,list0.length));
                        list1=outParenthesis(list1);
                        model.value =list1;
                    }else if(model.type=='comment'){
                        list1=handleParenthesis(list0.slice(1,list0.length));
                        list1=outParenthesis(list1);
                        model.value =list1;
                    }else if(model.type=='execute'){
                        model.code=list0[1].type;
                        if(model.code=='list'){
                            model.source={};
                            model.source.type='variable';
                            model.source.variableName=list0[1].listSource;
                        }else if(model.code=='list2'){
                            list1=handleParenthesis(list0.slice(2,list0.length));
                            list1=outParenthesis(list1);
                            model.value=list1;
                        }else if(model.code=='listEnd'||model.code=='listBreak'||model.code=='listContinue'){
                            //不走else ，不建立value节点，不然后台解析冲突
                        }else if(model.code=='judge'||model.code=='elseJudge'){
                            list1=handleParenthesis(list0.slice(2,list0.length));
                            list1=outParenthesis(list1);
                            model.source =list1;
                        }else if(model.code=='judgeEnd'||model.code=='else'){
                            model.source={};
                            model.source.type='const';
                            if(model.code=='judgeEnd'){
                                model.source.value="}";
                            }else if(model.code=='else'){
                                model.source.value="}else{";
                            }
                        }else{
                            list1=handleParenthesis(list0.slice(1,list0.length));
                            list1=outParenthesis(list1);
                            model.value =list1;
                        }
                    }
                    thenList.push(model);
                }
                return thenList;
            }

            function outParenthesis(list){
                var methodList=[];
                var list1=[];
                var list2=[];
                var list3=[];
                var list4=[];

                for(var i=0;i<list.length;i++){
                    var model = {};
                    if(list[i].type=='lastDateTime'||list[i].type=='addHours'||list[i].type=='countHours'||list[i].type=='startWith'||list[i].type=='endsWith'||list[i].type=='matchWith'||list[i].type=='matcher'){
                        // model.type =list[i].type;
                        model=list[i];
                        model.source=list[i-1];
                        methodList.pop();
                        methodList.push(model);
                        list[i-1]=model;
                    }else if(list[i].type=='compareHour'||list[i].type=='replaceDate'){
                        model=list[i];
                        model.source=list[i-1];
                        model.hours=list[i+1];
                        methodList.pop();
                        methodList.push(model);
                        list[i-1]=model;
                        list[i+1]=model;
                        i++;
                    }else if(list[i].type=='compareHour'||list[i].type=='replaceDate'){
                        model=list[i];
                        model.source=list[i-1];
                        model.hours=list[i+1];
                        methodList.pop();
                        methodList.push(model);
                        list[i-1]=model;
                        list[i+1]=model;
                        i++;
                    }else {
                        methodList.push(list[i]);
                    }
                }
                for(var i=0;i<methodList.length;i++){
                    var model = {'oper':{},'left':{'type':'','value':''},'right':{'type':'','value':''}};
                    if(methodList[i].oper!=null&&(methodList[i].oper=="*"||methodList[i].oper=="/")){
                        model.oper=methodList[i].oper;
                        model.left=methodList[i-1];
                        model.right=methodList[i+1];
                        list1.pop();
                        list1.push(model);
                        methodList[i-1]=model;
                        methodList[i+1]=model;
                        i++;
                    }else{
                        list1.push(methodList[i]);
                    }
                }

                for(var i=0;i<list1.length;i++){
                    var model = {'oper':{},'left':{'type':'','value':''},'right':{'type':'','value':''}};
                    if(list1[i].oper!=null&&(list1[i].oper=="+"||list1[i].oper=="-")){
                        model.oper=list1[i].oper;
                        model.left=list1[i-1];
                        model.right=list1[i+1];
                        list2.pop();
                        list2.push(model);
                        list1[i-1]=model;
                        list1[i+1]=model;
                        i++;
                    }else{
                        list2.push(list1[i]);
                    }
                }
                for(var i=0;i<list2.length;i++){
                    var model = {'oper':{},'left':{'type':'','value':''},'right':{'type':'','value':''}};
                    if(list2[i].oper!=null&&(list2[i].oper=="<"||list2[i].oper==">"||list2[i].oper=="=="||list2[i].oper==">="||list2[i].oper=="<="||list2[i].oper=="!=")){
                        model.oper=list2[i].oper;
                        model.left=list2[i-1];
                        model.right=list2[i+1];
                        list3.pop();
                        list3.push(model);
                        list2[i-1]=model;
                        list2[i+1]=model;
                        i++;
                    }else{
                        list3.push(list2[i]);
                    }
                }
                for(var i=0;i<list3.length;i++){
                    var model = {'oper':{},'left':{'type':'','value':''},'right':{'type':'','value':''}};
                    if(list3[i].oper!=null&&(list3[i].oper=="&&"||list3[i].oper=="||"||list3[i].oper=="unit||"||list3[i].oper=="unit&&")){
                        model.oper=list3[i].oper;
                        model.left=list3[i-1];
                        model.right=list3[i+1];
                        list4.pop();
                        list4.push(model);
                        list3[i-1]=model;
                        list3[i+1]=model;
                        i++;
                    }else{
                        list4.push(list3[i]);
                    }
                }

                if(list4.length>1){
                    GillionMsg.alert('提示', "配置出错啦，请检查！");
                    throw new Error('配置出错啦');
                }
                return list4[0];
            }
            function showEdit($scope,type){
                var  leftBracketNodes= $("[name='leftBracket']");
                var  rightBracketNodes= $("[name='rightBracket']");
                var  attributeCheck = $(".attribute-check");
                //左右括号及节点高亮显示时不触发事件
                if(leftBracketNodes.length==0&&rightBracketNodes.length==0&&attributeCheck.length==0) {
                    if (type == "node") {
                        var node = angular.element("#" + event.target.id);
                        if (event.target.tagName!="SPAN") {
                            node = node.parent();
                        }
                        node.removeClass();
                        node.addClass("attribute-on");
                        var childrenNode = node.children();
                        var childNode = angular.element("#" + childrenNode[0].id);
                        childNode.addClass("attribute-on-c");
                        var num = childNode.attr("id").replace("node", "");
                        childNode.after(
                            $compile(
                                "<div class='top' id='removeTop' ><a href='javascript:void(0)' ng-click='removeCondition(" + num + ")'>×</a></div>" +
                                "<div class='left' id='addLeft'><a href='javascript:void(0)' ng-click='addFront(" + num + ")'>＋</a></div>" +
                                "<div class='right' id='addRight'><a href='javascript:void(0)' ng-click='addBehind(" + num + ")'>＋</a></div>"
                            )($scope)
                        );
                    }
                }
            }

            function closeEdit(type,state){
                if(type=="node") {
                    var node ;
                    //当由右侧移出时，获取到的是a标签，其他获取到的是div，进行区别处理
                    if(event.target.tagName=="A"&&(event.target.id==undefined||event.target.id=="")){
                        node = angular.element("#" + event.target.parentElement.id)
                    }else {
                        node = angular.element("#" + event.target.id);
                    }
                    if(state=="edit"&&event.target.tagName!="SPAN"){
                        node = node.parent();
                    }
                    node.removeClass("attribute-on");
                    var childrenNode =node.children();
                    for (var i = 0; i < childrenNode.length; i++) {
                        var childNode = angular.element("#" + childrenNode[i].id);
                        if(i==0){
                            childNode.removeClass("attribute-on-c");
                        }else{
                            childNode.remove();
                        }
                    }
                }
            }


            return {
                showThen: function(list) {
                    return showThen(list);
                },
                showRule: function(json) {
                    return showRule(json);
                },
                setHtml:function($scope,list,type){
                    return setHtml($scope,list,type);
                },
                init:function($scope){
                    return init($scope);
                },
                addConditionRow:function($scope,type,conditionList,isButton){
                    return addConditionRow($scope,type,conditionList,isButton);
                },
                addThen:function($scope,type,thenList,isButton){
                    return addThen($scope,type,thenList,isButton);
                },
                changeThen:function($scope,click){
                    return changeThen($scope,click);
                },
                change:function($scope,click){
                    return change($scope,click);
                },
                addRowCondition:function($scope,index){
                    return  addRowCondition($scope,index);
                },
                addRowThen:function($scope,index){
                    return addRowThen($scope,index);
                },
                copyCRow:function($scope,index){
                    return copyCRow($scope,index);
                },
                copyTRow:function($scope,index){
                    return copyTRow($scope,index);
                },
                show:function($scope,type,model,showType){
                    return show($scope,type,model,showType);
                },
                viewObject:function($scope,id,margin){
                    return viewObject($scope,id,margin);
                },
                addButton:function($scope){
                    return addButton($scope);
                },
                addEntry:function($scope){
                    return addEntry($scope);
                },
                addDict:function($scope,item){
                    return addDict($scope,item);
                },
                addSign:function($scope,value){
                    return addSign($scope,value);
                },
                addModel:function($scope,value){
                    return addModel($scope,value);
                },
                addVariable:function($scope,value){
                    return addVariable($scope,value);
                },
                addMethod:function($scope,value,text){
                    return addMethod($scope,value,text);
                },
                addFront:function($scope,value){
                    return addFront($scope,value);
                },
                addBehind:function($scope,value){
                    return addBehind($scope,value);
                },
                getResult:function(list){
                    return getResult(list);
                },
                getCondition:function(list){
                    return getCondition(list);
                },
                showEdit:function($scope,type){
                    return showEdit($scope,type);
                },
                closeEdit:function(type,state){
                    return closeEdit(type,state);
                },
                upThen:function($scope,index){
                    return upThen($scope,index);
                },
                downThen:function($scope,index){
                    return downThen($scope,index);
                },
                upCondition:function($scope,index){
                    return upCondition($scope,index);
                },
                downCondition:function($scope,index){
                    return downCondition($scope,index);
                },
            };
        }])
});